import {Component, OnInit, ViewEncapsulation, ChangeDetectionStrategy, ChangeDetectorRef} from '@angular/core';
import {PlanService} from "@train/plan/plan.service";
import {ActivatedRoute, Params} from "@angular/router";
import {TrainClassScheduleVO, TrainSchedulePlanVO} from "@interface/index";

@Component({
  selector: 'seed-teching-detail',
  templateUrl: './teching-detail.component.html',
  styleUrls: ['./teching-detail.component.scss'],
  encapsulation: ViewEncapsulation.None,
})
export class TechingDetailComponent implements OnInit {
  public lessonInfo: TrainSchedulePlanVO;
  public dataStore = {
    lessonTitle: '',
    lessonNum: 0,
    classScheduleId: 0
  };

  constructor(private _planService: PlanService,
              private _route: ActivatedRoute) {

    this._route.params.switchMap((params: Params) => {
      if (params['classScheduleId']) {
        this.dataStore.classScheduleId = params['classScheduleId'];
        this.getLessonPlanInfo(params['classScheduleId']);
      }
      return this._route.queryParams;
    }).subscribe((params: TrainClassScheduleVO) => {
      this.dataStore.lessonTitle = decodeURI(params['subjectName']);
      this.dataStore.lessonNum = params['lessonNum'];
    });
  }

  /**
   * @description 获取课时计划
   * @author ouyqx-691
   * @date 2018-3-30
   * @param scheduleId : 课时ID
   */
  getLessonPlanInfo(scheduleId: number) {
    this._planService.getLessonPlanInfo(scheduleId).subscribe((res) => {
      if (res.result === '0' && res.data) {
        this.lessonInfo = res.data;
      }
    });
  }

  ngOnInit() {
  }
}
